package com.itcast.springboot3x.config;

import com.itcast.springboot3x.http.client.ToDoBeanClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@Configuration
public class HttpClientConfig {
    @Bean
    public ToDoBeanClient todoBeanClient() {
        WebClient webClient = WebClient.builder().baseUrl("https://jsonplaceholder.typicode.com").build() ;

        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder().clientAdapter(WebClientAdapter.forClient(webClient)).build() ;
        return factory.createClient(ToDoBeanClient.class) ;
    }
}
